package com.aqie.demo.http_request_response;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * Request 数据可以重复读取， 添加注解扫描到这个filter
 * 解决 com.aqie.demo.filter_and_interceptor.WebInterceptorAdapter
 */
@Slf4j
// @WebFilter(urlPatterns = "/*", filterName = "RequestWrapperFilter")
public class RequestWrapperFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
                         FilterChain chain) throws IOException, ServletException {
        log.error("RequestWrapperFilter Replace InputStream!");

        ServletRequest requestWrapper =
                new RequestWrapper((HttpServletRequest) request);
        chain.doFilter(requestWrapper, response);
    }

    @Override
    public void destroy() {

    }
}
